﻿@model Physis.Client.Models.Configuration.UserAccountModel

@{ Layout = "~/Views/Configuration/ConfigurationItemMaster.cshtml"; }

<script type="text/javascript" src="~/Scripts/Application/Configuration/UserAccount.js"></script>


@section InlineStyles {

    <style type="text/css">

    .PropertyTable td { padding: 8px; }

    .PropertyTable td:first-child { font-weight: bold; }

    </style>       
    
}

@section ItemPropertyTabsContent_GeneralProperties {

    <table class="PropertyTable">
        
        <thead><tr><th style="width: 135px"></th><th></th></tr></thead>

        <tr>

            <td>Security Authority: </td>

            <td>@Model.UserAccount.SecurityAuthorityName
                
                @if (Model.UserAccount.Id != 0) { 
                    
                    <span>@Html.HiddenFor(model=>model.UserAccount.SecurityAuthorityId)</span>
                    
                }

            </td>

        </tr>
        
        <tr>

            <td>Distinguished Name: </td>

            <td>@Model.UserAccount.DistinguishedName@Html.HiddenFor(model=>model.UserAccount.DistinguishedName)</td>

        </tr>

        <tr>

            <td>Display Name: </td>

            <td>@Model.UserAccount.DisplayName@Html.HiddenFor(model=>model.UserAccount.DisplayName)</td>

        </tr>
        
        <tr>

            <td>Last Login: </td>

            <td>@((Model.UserAccount.LastLogin.HasValue) ? Model.UserAccount.LastLogin.Value.ToString ("MM/dd/yyyy hh:mm:ss") : String.Empty) @Html.HiddenFor(model=>model.UserAccount.LastLogin)</td>

        </tr>

    </table>
    
    @* THE BELOW ARE HIDDEN TEXT INPUTS FOR SERIALIZING THE GRID DATA BACK TO THE SERVER *@
                    
    <input id="RoleMembership" name="Role.Membership" type="hidden" />
    
}

@section ItemPropertyTabs {
    
    <li><a href="#PropertyTab_Register">Register</a></li>

    <li><a href="#PropertyTab_Roles">Roles</a></li>

    <li><a href="#PropertyTab_EffectivePermissions">Effective Permissions</a></li>

}

@section ItemPropertyTabsContent {
    
    <div id="PropertyTab_Register" class="PropertyTab TextNormal" style="padding: 8px;">
        
        <div style="padding: 8px;">

            <table class="PropertyTable">
        
                <thead><tr><th style="width: 125px"></th><th style="width: 250px"></th><th></th></tr></thead>

                <tr>

                    <td>Security Authority: </td>

                    <td>@Model.UserAccount.SecurityAuthorityName
                
                        @if (Model.UserAccount.Id == 0) { 
                    
                            <span>@Html.DropDownListFor(model=>model.UserAccount.SecurityAuthorityId, Model.SecurityAuthoritySelectList, new { style="width: 250px;", onchange="RegisterUserAccountGrid_Refresh();" })</span>
                    
                        }

                    </td>

                </tr>
        
                <tr>

                    <td>Account Name: </td>

                    <td><input id="UserAccountName" type="text" style="width: 247px;" /></td>

                    <td><a href="javascript:void(0);" onclick="RegisterUserAccountGrid_Refresh();">(search)</a></td>

                </tr>
            
        
                <tr>

                    <td>Selected Account: </td>

                    <td colspan="2"><label id="RegisterUserAccountSelected">(none)</label></td>

                </tr>

            </table>

        </div>

        <div style="margin: 8px;">

            <table id="RegisterUserAccountGrid"></table>

            <div id="RegisterUserAccountGridPager"></div>

        </div>

    </div>

    <div id="PropertyTab_Roles" class="PropertyTab TextNormal" style="padding: 8px;">
        
        <div style="padding: 8px;">

            <table class="PropertyTable">
        
                <thead><tr><th style="width: 100px"></th><th style="width: 250px"></th><th></th></tr></thead>

                <tr>

                    <td>Environment: </td>

                    <td>@Html.DropDownList("Roles_EnvironmentSelection", Model.EnvironmentSelectList, new { style="width: 250px;", onchange="Roles_EnvironmentSelection_OnChange();" })</td>
                    
                    <td></td>

                </tr>
        
                <tr>

                    <td style="padding-bottom: 9px;">Role: </td>

                    <td>
                    
                        <div><select id="Roles_RoleSelection" style="width: 250px;"></select></div>
                            
                        <div id="Roles_RoleSelection_ProgressBar" style="width: 248px;"></div>

                    </td>
                    
                    <td><a id="Roles_RoleAdd" href="javascript:void(0);" onclick="Roles_RoleAdd_OnClick();">(add)</a></td>

                </tr>
                
                <tr><td colspan="3">
                    
                    <p style="font-weight: normal; margin: 4px;">Adding a user to an Environment Role will grant them permissions to access that associated environment. 

                        Removing them from all roles in an Environment will remove the user from that environment. 

                    </p> 

                </td></tr>

            </table>

        </div>
        
        <div style="margin: 0px 8px 8px 8px;">

            <table id="UserAccountRoleGrid"></table>

        </div>

    </div>
    
    <div id="PropertyTab_EffectivePermissions" class="PropertyTab TextNormal" style="padding: 8px;">
        
        <div style="padding: 8px;">

            <table class="PropertyTable">
        
                <thead><tr><th style="width: 100px"></th><th style="width: 250px"></th><th></th></tr></thead>

                <tr>

                    <td>Environment: </td>

                    <td>
                        
                        <div>@Html.DropDownList("EffectivePermissions_EnvironmentSelection", Model.EnvironmentSelectList, new { style="width: 250px;" })</div>

                        <div id="EffectivePermissions_EnvironmentSelection_ProgressBar" style="width: 248px;"></div>

                    </td>
                    
                    <td><a href="javascript:void(0);" onclick="EffectivePermissions_Calculate_OnClick();">(calculate)</a></td>

                </tr>
        
                <tr><td colspan="3">
                    
                    <p style="font-weight: normal; margin: .125in;">This will calculate the effective permissions that the user will have
                        
                        for a specific environment. Select the environment and click "calculate" to see the permissions aggregated from

                        all Roles the user is a member of in the environment.

                    </p> 

                </td></tr>
        
            </table>

        </div>
        
        <div style="margin: 8px;">

            <table id="EffectivePermissionsGrid"></table>

        </div>

    </div>
    
}

<script type="text/javascript">

    var environmentDictionary = @Html.Raw(Json.Encode(Model.Application.Core.CoreObjectDictionarySerializable (Model.Application.Enterprise.Environments().ConvertAll(environment => (Physis.Core.CoreObject) environment))));
    
    var userAccountRoles = @Html.Raw(Json.Encode(Model.UserAccount.Roles));
    
    var roleMembership = @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model.RoleMembership));

    var roleMembershipBaseObject = @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(new Physis.Security.RoleMembership (Model.Application)));

</script>